

public class Client {

    public interface IProduct{
        void doSomething();
    }

    //静态类：只能访问类内部的静态成员；
    //非静态类：可访问类内所有成员；
    static class ProductA implements IProduct{
        public void doSomething(){
            System.out.println("I am Produuct A");
        }
    }

    static class ProductB implements IProduct{
        public void doSomething(){
            System.out.println("I am Produuct B");
        }
    }

    static class ProductC implements IProduct{
        public void doSomething(){
            System.out.println("I am Produuct C");
        }
    }

    enum ProductType{
        PRODUCT_A,
        PRODUCT_B,
        PRODUCT_C
    }

    static class SimpleFactory{
        public static IProduct makeProduct(ProductType type){
            switch (type){
                case PRODUCT_A:
                    return new ProductA();
                case PRODUCT_B:
                    return new ProductB();
                case PRODUCT_C:
                    return new ProductC();
            }
            return null;
        }
    }

    public static void main(String[] args) {
        System.out.println(ProductType.PRODUCT_A.ordinal());
        IProduct product = new SimpleFactory().makeProduct(ProductType.PRODUCT_A);
        product.doSomething();
    }

}
